package com.gwnet.rider.controller;

import com.gwnet.common.bean.vo.LoginVO;
import com.gwnet.common.config.WxConfig;
import com.gwnet.common.core.domain.ResponseResult;
import com.gwnet.rider.domain.bo.RiderUserLoginBO;
import com.gwnet.rider.service.RiderLoginService;
import com.gwnet.user.entity.bo.CodeLoginBO;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 骑手登录
 * @author: WangLiang
 * @date: 2024/7/31 8:03
 */
@RestController
@RequestMapping("/riderLogin")
public class RiderLoginController {

    private final WxConfig wxConfig;
    private final RiderLoginService riderLoginService;

    public RiderLoginController(WxConfig wxConfig, RiderLoginService riderLoginService) {
        this.wxConfig = wxConfig;
        this.riderLoginService = riderLoginService;
    }


    /**
     * 根据微信的code登录
     * @param codeLoginBO
     * @return
     * @throws WxErrorException
     */
    @PostMapping("/loginByCode")
    public ResponseResult<LoginVO> loginByCode(@RequestBody CodeLoginBO codeLoginBO) throws WxErrorException {
        LoginVO loginVO = riderLoginService.loginByCode(codeLoginBO.getCode());
        return ResponseResult.success(loginVO);
    }

    /**
     * 根据账号和密码登录，同时绑定到openId
     * @param loginBO
     * @return
     * @throws WxErrorException
     */
    @PostMapping("/loginByAccount")
    public ResponseResult<LoginVO> loginByAccount(@RequestBody RiderUserLoginBO loginBO) throws WxErrorException {
        LoginVO loginVO = riderLoginService.loginByAccount(loginBO);
        return ResponseResult.success(loginVO);
    }

}
